/// [Longest Collatz sequence](https://projecteuler.net/problem=14)
fn main() {
    for length in &[100, 1000000] {
        println!("{:?}", longest_collatz_sequence(*length));
    }
}
fn longest_collatz_sequence(length: u64) -> (u64, u64) {
    let mut max = (0, 0);
    for n in 2..length {
        let mut m = 1;
        let mut tmp = n;
        while tmp > 1 {
            if tmp % 2 == 0 {
                tmp = tmp / 2;
            } else {
                tmp = tmp * 3 + 1;
            }
            m += 1;
        }
        if max.1 < m {
            max = (n, m)
        }
    }
    max
}
